package com.hotel.controller;

import com.hotel.pojo.Temporary;
import com.hotel.service.TemporaryService;
import com.hotel.vo.PageResult;
import com.hotel.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/temporary")
public class TemporaryController {
    @Autowired
    private TemporaryService temporaryService;

    @GetMapping("/findAll")
    public List<Temporary> findAll(){
        return temporaryService.findAll();
    }

    /**
     * 增加订单
     */
    @PostMapping("/addTemporary")
    public SysResult addTemporary(@RequestBody Temporary temporary){
        temporaryService.addTemporary(temporary);
        return SysResult.success();
    }

    /**
     * 展示列表并分页查询
     * @param pageResult
     * @return
     */
    @GetMapping("/temporaryList")
    public SysResult temporaryList(PageResult pageResult){
        pageResult = temporaryService.temporaryList(pageResult);
        return SysResult.success(pageResult);
    }

    /**
     * 根据ID删除
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public SysResult deleteTemporary(@PathVariable Integer id){
        temporaryService.deleteTemporary(id);
        return SysResult.success();
    }
}
